<?php
/**
 * Created by PhpStorm.
 * User: KaZeline
 * Date: 15-6-25
 * Time: 下午5:40
 */
require_once("/var/www/html/new/conf/le.je");
require_once("/var/www/html/new/d/common/func.inc.php");
$le=new go_sql();
$le->connect();
$action = trim($_POST['action']);
switch ($action) {
    case 'single_salesID':
        $auth_array = array('yipiao'=>1,'yami'=>1,'kfb000'=>1,'csj1'=>1,'family'=>1);
        if(!$auth_array[$_SESSION['account']]){
            $le->close();
            exit('{"sta":"fail"}');
        }
        //只有燕枚,天荣,小妹的帐号能操作
        $id = $_POST['fid']+0;
        if(!$id) exit('{"sta":"fail"}');
        $salesID = $_POST['salesID']+0;
        $kefuID = $_POST['kefuID']+0;
        if((!checkData($_POST['protocal_start']) && !empty($_POST['protocal_start']))||(!checkData($_POST['protocal_end']) && !empty($_POST['protocal_end']))){
            $le->close();
            exit('{"sta":"fail"}');
        }
        $_POST['protocol_main'] = mysql_real_escape_string(safetxt($_POST['protocol_main']));
        $sql = "update pft_member set salesID=$salesID,kefuID=$kefuID where id=$id limit 1";
        if($le->query($sql)){
            $sql = "update pft_member_extinfo set
            protocol_start='{$_POST['protocal_start']}',protocol_end='{$_POST['protocal_end']}',protocol_main='{$_POST['protocol_main']}'
            where fid=$id limit 1";
            if($le->query($sql)){
                $le->close();
                exit('{"sta":"suc"}');
            }
            $le->close();
            exit('{"sta":"fail"}');
        }else{
            $le->close();
            exit('{"sta":"fail"}');
        }
        break;
    case 'get_salesID':
        $id = $_POST['fid']+0;
        if(!$id)    exit('{"sta":"fail"}');
        $sql = "select salesID,kefuID,protocol_start,protocol_end,protocol_main
        from pft_member m left join pft_member_extinfo e on m.id=e.fid
        where m.id=$id limit 1";
        $GLOBALS['le']->query($sql);
        $row = $GLOBALS['le']->fetch_assoc();
//        var_dump($row['protocol_main']);
        $row['protocol_main']= str_replace(PHP_EOL, '', $row['protocol_main']);
        $le->close();
        exit('{
            "sta":"suc",
            "salesID":'.$row['salesID'].',
            "kefuID":'.$row['kefuID'].',
            "protocol_start":"'.$row['protocol_start'].'",
            "protocol_end":"'  .$row['protocol_end'].'",
            "protocol_main":"' .$row['protocol_main'].'"
        }');
        break;
    case 'mid_dname'://数据图表的饼图要用到查会员名称的
        if(!an_verify($_POST))
            exit('error');
        $mid = mysql_real_escape_string($_POST['mid']);
        $sql = "select id,dname from pft_member where id in ($mid)";
        $GLOBALS['le']->query($sql);
        while($row=$GLOBALS['le']->fetch_assoc()){
            $r[$row['id']] = $row['dname'];
        }
        echo json_encode($r);
        break;
    case 'is_apply'://地图查是否是供应商
        if(!an_verify($_POST))
            exit('error');
    default:
        # code...
        break;
}
exit;
function an_verify($query){
    define('SEC_KEY','7d9d6op56gdg1524h3b8');
    return md5($query[0].SEC_KEY)==$query['token'];
}